//
//  GuidePageVIew.m
//  ThePrivateKitchen
//
//  Created by lirui on 16/1/28.
//  Copyright © 2016年 www.lanou3g.com蓝鸥科技. All rights reserved.
//

#import "GuidePageVIew.h"

@implementation GuidePageVIew
{
    NSInteger pageCount;
    UIPageControl *pageControl;
    UIScrollView *_scrollView;
    NSMutableArray *picArray;
}
-(instancetype)init
{
    self = [ super init];
    if (self) {
        self.frame = CGRectMake(0,0 , WIDTH * 375, HEIGHT*667);
    }
    return self;
}
-(void)setPic:(NSMutableArray *)picArr
{
    pageCount = picArr.count;
    picArr =[ NSMutableArray arrayWithArray:picArr];
    
    _scrollView =[[ UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH *375, HEIGHT *667)];
    _scrollView.contentSize = CGSizeMake(WIDTH *375 * pageCount  , HEIGHT *667);
    _scrollView.pagingEnabled = YES;
    _scrollView.backgroundColor= [ UIColor clearColor];
    _scrollView.delegate = self;
    _scrollView.showsHorizontalScrollIndicator =NO;
    _scrollView.showsVerticalScrollIndicator = NO;
    _scrollView.bounces = NO;
    [self addSubview:_scrollView];
    pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, HEIGHT *667 - 40, WIDTH *375, 20)];
    pageControl.numberOfPages = picArr.count;
    pageControl.currentPage = 0;
    pageControl.currentPageIndicatorTintColor = [UIColor yellowColor];
     pageControl.pageIndicatorTintColor = [UIColor redColor];
    [self addSubview:pageControl];
    for (NSInteger i = 0; i < picArr.count; i++) {
        UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH *i*375 , 0, WIDTH *375 , HEIGHT *667)];
        //img.contentMode = UIViewContentModeScaleAspectFill;
        img.backgroundColor = [ UIColor clearColor];
        NSString *picName = picArr[i];
        img.image = [UIImage imageNamed:picName];
        [_scrollView addSubview:img];
        [img release];
        UIButton *button =[UIButton buttonWithType:UIButtonTypeCustom];
        [button setFrame:CGRectMake((picArr.count - 1) * WIDTH *375 + WIDTH*375 / 2 + 10 *WIDTH, HEIGHT *667* 0.88, 120 * WIDTH, HEIGHT*40)];
        [button setTitle:@"进入" forState:UIControlStateNormal];
        [button.titleLabel setFont:[UIFont systemFontOfSize:22]];
        button.layer.cornerRadius = 5;
        button.layer.borderWidth = 2;
        button.layer.masksToBounds = YES;
        button.layer.borderColor = [UIColor whiteColor].CGColor;
        
        [button setTitleColor: [UIColor colorWithRed:0.78 green:0.34 blue:0.31 alpha:1]forState:UIControlStateNormal];
        [button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
        [_scrollView addSubview:button];

    }
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    CGFloat contentOffx = scrollView.contentOffset.x;
    NSInteger currentPage = contentOffx /(WIDTH *375);
    pageControl.currentPage = currentPage;
//    if (contentOffx > WIDTH *375 *(pageCount -1)) {
//      
//    }
}
-(void)buttonClick
{
     [self.delegate GuidePageViewEndGuide];
}
@end
